package com.ruoyi.web.controller.fuwu;

import java.util.List;

import com.ruoyi.system.service.IRepaircarService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Repaircar;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 修车服务 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/repaircar")
public class RepaircarController extends BaseController
{
    private String prefix = "system/repaircar";
	
	@Autowired
	private IRepaircarService repaircarService;
	
	@RequiresPermissions("system:repaircar:view")
	@GetMapping()
	public String repaircar()
	{
	    return prefix + "/repaircar";
	}
	
	/**
	 * 查询修车服务列表
	 */
	@RequiresPermissions("system:repaircar:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Repaircar repaircar)
	{
		startPage();
        List<Repaircar> list = repaircarService.selectRepaircarList(repaircar);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出修车服务列表
	 */
	@RequiresPermissions("system:repaircar:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Repaircar repaircar)
    {
    	List<Repaircar> list = repaircarService.selectRepaircarList(repaircar);
        ExcelUtil<Repaircar> util = new ExcelUtil<Repaircar>(Repaircar.class);
        return util.exportExcel(list, "repaircar");
    }
	
	/**
	 * 新增修车服务
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存修车服务
	 */
	@RequiresPermissions("system:repaircar:add")
	@Log(title = "修车服务", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Repaircar repaircar)
	{		
		return toAjax(repaircarService.insertRepaircar(repaircar));
	}

	/**
	 * 修改修车服务
	 */
	@GetMapping("/edit/{repaircarId}")
	public String edit(@PathVariable("repaircarId") Integer repaircarId, ModelMap mmap)
	{
		Repaircar repaircar = repaircarService.selectRepaircarById(repaircarId);
		mmap.put("repaircar", repaircar);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存修车服务
	 */
	@RequiresPermissions("system:repaircar:edit")
	@Log(title = "修车服务", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Repaircar repaircar)
	{		
		return toAjax(repaircarService.updateRepaircar(repaircar));
	}
	
	/**
	 * 删除修车服务
	 */
	@RequiresPermissions("system:repaircar:remove")
	@Log(title = "修车服务", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(repaircarService.deleteRepaircarByIds(ids));
	}

	/**
	 * 修改修车服务状态
	 * @param repaircar
	 * @return
	 */
	@Log(title = "修车服务", businessType = BusinessType.UPDATE)
	@RequiresPermissions("system:repaircar:edit")
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(Repaircar repaircar)
	{
		return toAjax(repaircarService.updateRepaircar(repaircar));
	}
	
}
